package org.example.work2.at.account.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.work2.at.account.dto.Account;
import org.example.work2.at.account.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/account")
public class AccountController {
	
	@Autowired
    private AccountService accountService;
	
	/**
	 *    提供查询验证账户信息
	 * @param accountCode
	 * @return
	 */
	@GetMapping("/findAccountByCode/{accountCode}")
	public Account findAccountByCode(@PathVariable("accountCode") String accountCode) {
		System.out.println("订单服务发起远程调用查询用户信息");
		Account account= accountService.findAccountByCode(accountCode);
		System.out.println("查询结果account="+account);
		return account;
    }

	@PutMapping("/scores")
	public boolean updateScores(@RequestBody Account account) throws Exception {
		log.info("[updateScores] 收到更新账户信息请求, 用户:{}, 积分:{}", account.getAccountCode(), account.getReduceScores());
		return accountService.updateScores(account);
	}
}
